<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<?php include(DDROOTPATH.'/cache/title/'.$pagetag.'_title.php');?>
<link href="template/<?=MOBAN?>/css/style.css" rel="stylesheet" type="text/css" />
<link href="template/<?=MOBAN?>/css/layout.css" rel="stylesheet" type="text/css" />
<link href="template/<?=MOBAN?>/css/comm.css" rel="stylesheet" type="text/css" />
<link href="template/<?=MOBAN?>/css/baobei.css" rel="stylesheet" type="text/css" />

<link href="template/<?=MOBAN?>/css/redirect.css" rel="stylesheet" type="text/css" />

<script language="javascript" type="text/javascript" src="template/<?=MOBAN?>/js/jquery.js"></script>
<SCRIPT type="text/javascript" src="template/<?=MOBAN?>/js/base64.js"></SCRIPT>
<SCRIPT type="text/javascript" src="template/<?=MOBAN?>/js/function.js"></SCRIPT>
<script type="text/vbscript">
Function str2asc(strstr)
str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
asc2str = chr(ascasc)
End Function
</script>
<script language="JavaScript" type="text/javascript">
<!-- 
function imgAuto(img, maxW, maxH) {
	var oriImg = document.createElement("img");
	oriImg.onload = function(){
		if (oriImg.width == 0 || oriImg.height == 0)
			return;
		var oriW$H = oriImg.width / oriImg.height;
		// var maxW$H = maxW / maxH;

		if (oriImg.height > maxH) {
			img.height = maxH;
			// img.removeAttribute("width");
			img.width = maxH * oriW$H;
		}
		if (img.width > maxW) {
			img.width = maxW;
			// img.removeAttribute("height");
			img.height = maxW / oriW$H;
		}

		if (maxH) {// if it defined the maxH argument
			if (img.height > 0)
				img.style.marginTop = (maxH - img.height) / 2 + "px";
		}
	};
	oriImg.src = img.src;
}
//-->
commentDefaultVal='说说你对这件宝贝的评价吧';

function OnClick(id)
{
  for(i=1;i<=10;i++)
  {
	  document.getElementById("b_"+i).className="bshop1";
  }	
  document.getElementById("b_"+id).className="bshop2";
  var typeid=document.getElementById("b_"+id).name;
  document.getElementById("shopid").value=typeid;
}

function shsend(type)
{
	if(type==1) //显示
	{
		document.getElementById("send1").style.display="block";
		document.getElementById("send2").style.display="block";
		document.getElementById("shop1").style.display="none";
		document.getElementById("shop2").style.display="none";
		document.getElementById("jt1").style.display="none";
	}
	if(type==2) //隐藏
	{
		document.getElementById("send1").style.display="none";
		document.getElementById("send2").style.display="none";
		document.getElementById("shop1").style.display="block";
		document.getElementById("shop2").style.display="block";
		document.getElementById("jt1").style.display="block";	
	}
}

function addExpression(myField, myValue)
{
    myField = document.getElementById(myField);
	if(myField.value==commentDefaultVal) myField.value='';
    //IE
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        myValue = myValue;
        sel.text = myValue;
        sel.select();
    }
    //MOZILLA
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        // save scrollTop before insert
        var restoreTop = myField.scrollTop;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length);
        if (restoreTop > 0)
        {
            // restore previous scrollTop
            myField.scrollTop = restoreTop;
        }
        myField.focus();
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    }
    else
    {
        myField.value += myValue;
        myField.focus();
    }
}

$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
msgErr=new Array();
msgErr[5]='您已经分享过这件商品';
msgErr[6]='您没有购买过商品，不能评论';
msgErr[7]='您提交的信息不全';
msgErr[8]='评论不能为空或者含有敏感词';
msgErr[9]='必须添加图片';
msgErr[15]='此商品已有人分享过，换换别的吧，O(∩_∩)O';

function closeShare(){
    $('.LightBox').hide();
	$('#jumpbox2').hide();
	$('#title').val('');
	$('#url').val('');
	$('#price').val('');
	$('#tao_img').val('');
	$('#keywords').val('');
	$('#comment').val(commentDefaultVal);
	$('#J_ImgBooth').attr('src','images/ad.jpg');
	$('#num').text(80);
}

/*这里开始时UrlEncode和UrlDecode函数*/
function UrlEncode(str){
var ret="";
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
var tt= "";

for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
var c=str2asc(chr);
tt += chr+":"+c+"n";
if(parseInt("0x"+c) > 0x7f){
ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
}else{
if(chr==" ")
ret+="+";
else if(strSpecial.indexOf(chr)!=-1)
ret+="%"+c.toString(16);
else
ret+=chr;
}
}
return ret;
}
function UrlDecode(str){
var ret="";
for(var i=0;i<str.length;i++){
var chr = str.charAt(i);
if(chr == "+"){
ret+=" ";
}else if(chr=="%"){
var asc = str.substring(i+1,i+3);
if(parseInt("0x"+asc)>0x7f){
ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
i+=5;
}else{
ret+=asc2str(parseInt("0x"+asc));
i+=2;
}
}else{
ret+= chr;
}
}
return ret;
}

function getTaoItem(url){
    if(url==''){
		alert('网址不能为空！');
	}
	else{
		if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
		}
		else{
			$('#J_ImgBooth').attr('src','images/wait.gif');
		    $.post("a.php",{'fun':'get_tao_img','url':url,'xs':'share'},function(data){//alert(data);
		        var data= eval("(" + data + ")");
				$('#radio'+data.cid).attr("checked",true);
		        $('#title').val(data.title);
				$('#price').val(data.price);
				$('#url').val(url);
			    $('#J_ImgBooth').attr('src',data.img);
				$('#tao_img').val(data.img);
			    $('#dopic').hide('normal');
				clickUrl=data.clickUrl;
				nick=data.nick;
		    });
		}
	}
}

regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
$(function(){
    $('.close').click(closeShare);
	$('#noShare').click(function(){alert('您的等级不足，不能分享宝贝！');});
	$('#startShare').click(function(){
		dduserid=<?=$_SESSION['dduserid']?$_SESSION['dduserid']:0?>;
		if(dduserid>0){
			shsend(2);
		    $('.LightBox').show();
			$('#jumpbox2').show();
			$('#jiantou').css('left','118px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#dopic').show('normal');
			$('#tao_url').val('在这里粘贴宝贝的链接地址');
		}
		else{
		    alert('登陆后才可分享商品！');
			window.location='user/login.php?url='+encodeURIComponent(location.href);
		}
	    
	});
	/*$('#url').blur(function(){
		var url=$('#url').val();
		if(url!=''){
		    getTaoItem(url);
		}
	});*/
	$('#get_tao_img').click(function(){
	    var url=$('#tao_url').val();
		var f=$(this).attr('f');
		if(f=='html'){
			getTaoItem(url);
		}
		else if(f=='jpg'){
			if(url==''){
		        alert('网址不能为空！');
	        }
			else{
			    $('#J_ImgBooth').attr('src',url);
			    $('#tao_img').val(url);
			    $('#dopic').hide('normal');
			}
		} 
	});
	$('#shaiForm').submit(function(){
        var title=$('#title').val();
		var url=$('#url').val();
		var price=$('#price').val();
		var tao_img=$('#tao_img').val();
		var keywords=jQuery.trim($('#keywords').val());
		var comment=$('#comment').val();
		//temp = comment.replace(/{.*?}/gim,""); //过滤表情字符
		var catid = $('#shopid').val();
        var l=keywords.split(/\s+/).length;
		var num=parseInt($('#num').text());
		var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
		if(title==''){
		    alert('填写商品名称！');
			$('#title').focus();
		}
		else if(url==''){
		    alert('填写商品网址！');
			$('#url').focus();
		}
		else if (!url.match(regExp)){
		    alert('这不是一个淘宝网址！');
			$('#url').focus();
		}
		else if(price==''){
		    alert('填写商品价格！');
			$('#price').focus();
		}
		else if(tao_img=='' || tao_img=='../images/wait.gif' || tao_img=='_310x310.jpg'){
		    alert('商品加载失败！');
			/*$('#jiantou').css('left','80px');
		    $('#tishi').html('在此直接粘贴宝贝的链接地址');
			$('#picFun').show();
		    $('#dopic').show('normal');*/
		}
		else if(typeof catid=='undefined'){
		    alert('选择分类');
		}
		/*else if(temp==''){
		    alert('说点什么吧，不要只发表情哦');
		}*/
		else if(num<0){
		    alert('内容超限！');
			$('#comment').focus();
		}
		else if(comment=='' || comment==commentDefaultVal){
		    alert('请添加评论内容！');
			$('#comment').focus();
		}
		else if(l>5){
		    alert('最多填写5个关键词');
			$('#keywords').focus();
		}
		else{
			$('#subShare').attr('disabled','disabled');
		    $.post("a.php",{fun:'save_share',title:title,url:url,price:price,image:tao_img,keywords:keywords,comment:comment,catid:catid,'click_url':clickUrl,'nick':nick},function(data){//$('#title').val(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
				    alert('提交成功');
					$('#subShare').attr('disabled','');
					//document.execCommand('Refresh');//closeShare();
					location.replace(location.href);
					$('#jumpbox2').hide();
				}
				else{
				    alert(msgErr[data.msg]);
					$('#subShare').attr('disabled','');
				}
		    });
		}
		return false;
	});
	$('#comment').bind('focus keyup input paste',function(){  //采用几个事件来触发（已增加鼠标粘贴事件）   
	     $('#num').text(80-$(this).attr("value").length)  //获取评论框字符长度并添加到ID="num"元素上  
	});
	$('#openem').click(function(){
	    var left=$(this).attr('left');
		var tishi=$(this).attr('val');
		var f=$(this).attr('f');
		if(f=='jpg'){$('#tao_url').val('');}
		$('#jiantou').css('left',left);
		$('#tishi').html(tishi);
		$('#dopic').show('normal');
		$('#get_tao_img').attr('f',f);
	});
})
</script> 
</head>

<body>
<?php
$modtag="bblist";
include("head_shop.tpl.php");
?>
<div id="Content" class="clearfix MarginT10">
  <dl class="sharelist">
  <dt class="clearfix">
  <ul>
  <li><a <?php if($catid==''){?> class="active"<?php }?> href="userbao<?=$url_head_id?><?=$userid?>">全部分享</a></li>
  <?php foreach($shaicat_arr as $k=>$v){?>
  <li><a <?php if($k==$catid){?> class="active"<?php }?> href="baobeilist<?=$url_head_id?><?=$userid?><?=WJT?'-':'&catid='?><?=$k?><?=$url_head_xs?><?=$xs?><?=$url_head_page?>1<?=$url_end?>"><?=$v?></a></li>
  <?php }?>
  </ul>
  </dt>
  <dd>
  <ul>
  <li><a href="baobeilist<?=$url_head_catid?><?=$catid?><?=$url_head_sort?>id<?=$url_head_key?><?=$url_head_page?>1<?=$url_end?>" <?php if($sort=='id'){echo "class=\"active\"";}else{echo "class=\"MarginR0\"";}?>>最新宝贝</a></li>
  <li><a href="baobeilist<?=$url_head_catid?><?=$catid?><?=$url_head_sort?>hart<?=$url_head_key?><?=$url_head_page?>1<?=$url_end?>"  <?php if($sort=='hart'){echo "class=\"active\"";}else{echo "class=\"MarginR0\"";}?>>最热宝贝</a></li>
  </ul>
  </dd>
  </dl>
  <div class="clears"></div>
  <div class="MarginB10"><img src="template/<?=MOBAN?>/images/sharemylove.gif" width="982" height="66" border="0" usemap="#Map" />
    <map name="Map" id="Map">
      <area shape="rect" coords="16,13,129,54" href="javascript:void();"  <?php if($_SESSION['dduserid']>0 && $buyid==0){?> id="noShare" <?php }else{?> id="startShare"<?php }?> />
    </map>
  </div>
</div>

<div class="bblist">
  <?php
  $shaidan_num=count($shaidan_arr);
  ?>
  <?php for($j=0;$j<$shaidan_num;$j++){?>
 <div class=item1>
   <div class="picbox"><a href="baobei<?=$url_head_id?><?=$shaidan_arr[$j]['id']?><?=$url_end?>" target="_blank"><?=html_img($shaidan_arr[$j]['image'],$shaidan_arr[$j]['title'],'goods_list_img_i',200,'')?></a></div>
   <div class="line">
     <div class="box" style="background:url(template/<?=MOBAN?>/images/like.gif) left;cursor:pointer;width:63px" onclick="likek(<?=$shaidan_arr[$j]['id']?>)" title="送红心" ></div>
	 <div class="box" style="background:#000;width:30px;line-height:29px;text-align:center;color:#FFF" id="x_<?=$shaidan_arr[$j]['id']?>"><?=$shaidan_arr[$j]['hart']?></div>
     <div class="box" style="float:right;height:14px;margin-top:10px">
     	<a href="baobei<?=$url_head_id?><?=$shaidan_arr[$j]['id']?><?=$url_end?>#p" target="_blank"><img src="template/<?=MOBAN?>/images/pl.gif" width="22" height="13" border="0" /> 评论</a>
     </div>
   </div>
   <div class="line" style="height:38px">
   	<div class="headbox"><img src="upload/avatar/<?=get_avatar_filepath($shaidan_arr[$j]['dduserid'], $size = 'small', $type = '')?>" width="34" height="34" border="0" /></div>
	<div class="t"><a href="userbao<?=$url_head_id?><?=$shaidan_arr[$j]['dduserid']?><?=$url_end?>"><?=$shaidan_arr[$j]['ddusername']?></a></div>
    <div class="t" style="margin-top:3px"><font style="font-size:12px;color:#57504f"><?=date('m月d日 H:i',$shaidan_arr[$j]['time'])?> 分享</font></div>	   
   </div>
   <div class="line" style="height:40px;overflow:hidden;margin-top:8px"><?=utf_substr(strip_tags($shaidan_arr[$j]['comment']),28)?></div>
 </div>
 <?php }?>
  <div class="megas512" style="text-align:right;float:right"><?php pageft($total,$pagesize,1,0,0,10,$page_mall_list); echo $pagenav;?></div>
</div>
<div class="lineclear"></div>

<?php 
	include ("footer.tpl.php");
?>

<script type="text/javascript">
	msg=new Array();
	msg[6]='您已经送过红心';
	msg[7]='登陆才能送红心哦';
	
	function likek(id){
		var user_hart=parseInt($("#x_"+id).text());
		$.post("a.php",{fun:'inc_hart',shai_id:id,xs:'share'},function(data){//alert(data);
			var data= eval("(" + data + ")");
			if(data.err==0){
				$("#x_"+id).text(user_hart+1);
			}
			else{
				alert(msg[data.msg]);
			}
		});
	};
</script>

<!--分享的浮动层--> 
<div class="fxframe" id="jumpbox2">
<div class="close"></div>
  <div class="fmbox">
   <div class="SelType">
    <ul>
        <?php $i=1; foreach($shaicat_arr as $k=>$v){?>
        <li><input type="button" value="<?=$v?>"  name="<?=$k?>" id="b_<?=$i?>" onclick="OnClick(<?=$i?>);"  class="bshop1" /></li>
        <?php $i++; }?>
        <input name="shaicat" type="hidden" id="shopid" value="" />
    </ul>
   </div>
   <div class="Enter">
      <div class="jt" id="jt1"></div>
      <form>
       <div class="Editfm" id="shop1"><textarea id="tao_url" class="text" >在这里张贴宝贝的地址</textarea></div>
       <div class="bfm" id="shop2"> <input  f='html' id="get_tao_img" type="button" class="bnt" onclick="shsend(1)"  value="确 定" /></div>
     </form>
     <form id="shaiForm">
     <div class="Editfm" id="send1"><textarea id="comment" onfocus="if(this.value==commentDefaultVal){this.value=''};" class="text" ><?php if($buyid==0){?>您的等级不足，不能分享宝贝！<?php }else{?>说说你对这件宝贝的评价吧<?php }?></textarea></div>
     <div class="bfm" id="send2"> <input id="subShare" type="submit" class="bnt"  value="发 布" <?php if($buyid==0){?> disabled="disabled"<?php }?>/></div>
     <div class="line">
       <a onclick="$('#expression1').fadeIn('slow');"  id="openem" class="bp"></a><a onclick="shsend(2)" class="tb"></a>
       <div class="rtxt" style="margin-right:80px">还可以输入<b id="num" style="font-size:14px; color:#FFF">80</b>个字</div>
     </div> 
       <input type="hidden" value="" id="trade_id" />
       <input type="hidden" value="" id="tao_img" /> 
     </form>  
   </div>
   <div class="shopInfo">
      <div class="shopic"><img id="J_ImgBooth" src="<?=$navheadurl?>images/ad.jpg" width="119" height="119" /></div>
      <div class="t">名称：<input readonly="readonly" id="title" type="text" style=" width:350px; height:20px; border:0; line-height:20px;background:#333;color:#FFF" /></div>
      <div class="t">链接：<input readonly="readonly" id="url" type="text" style=" width:350px; height:20px; border:0; line-height:20px;background:#333;color:#FFF" /></div>
      <div class="t">价格：<input readonly="readonly" type="text" style=" width:60px; height:20px;line-height:20px;border:0;background:#333;color:#FFF;font-size:12px" id="price" />元</div>
      <div class="t">标签：<input id="keywords" type="text" style=" width:316px; height:29px; border:1px solid #d2caca; line-height:29px;color:#c7c3c3" value="填写商品关键字，用空格隔开"  /></div>
   </div>
  </div>
  
  <!--表情层-->
  <div class="emfm" id="expression1">
   <div class="top"><img src="template/<?=MOBAN?>//images/bqjt.gif" height="12" width="11" border="0" style="margin-left:45px" /></div>
   <div class="SelEm">
    <div class="emlist">
       <ul>
		<?php foreach($expression as $k=>$v){?>
        <li><img src="<?=$navheadurl?>images/emoticons/<?=$k?>.gif" style="cursor:pointer" onclick="addExpression('comment','{<?=$v?>}');"/></li>
		<?php }?>
      </ul>
    </div>
    <a onclick="$('#expression1').fadeOut('slow');"><div class="emclose"></div></a>
   </div>
  </div>
</div>
<script type="text/javascript">
OnClick(1);
shsend(2);
</script>
</body>
</html>
